﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing.Imaging;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

namespace Networking
{
    class ScreenManager : IScreenManager
    {
        private static Bitmap bmpScreenshot;
        private static Graphics gfxScreenshot;
        
        public System.Drawing.Bitmap TakeScreenShot()
        {
            //hide the form so that it does not appear in the screenshot
            //this.Opacity = 0;

            //set the bitmap object to the size of the screen
            bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format48bppRgb);

            //create a graphics object from the bitmap
            gfxScreenshot = Graphics.FromImage(bmpScreenshot);

            //take the screenshot from the upper left corner to the lower right corner
            gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);

            //show the form again
            //this.Opacity = 100;

            return bmpScreenshot;
        }
    }
}
